Dynomotion

Group: DynoMotion Message: 7941 From: ericncn Date: 7/16/2013
Subject: sending ModBus msgs from KmotionCNC to a RS485 port
I've bought a VFD for controlling the spindle motor speed.
The VFD configuration software (running on PC side) talks to the VFD via an RS485 port installed on COM5, using the ModBus protocol.

(The RS485 on COM5 is actually a virtual port created by an USB-RS485 converter, but this should make no difference to our purpose.)

My question is: how do I send ModBus messages from KmotionCNC to the RS485 port on COM5 ?

Of course I would like to implement the M commands and the S command in order to control spindle start/stop, forward/reverse, and speed.

What are the main steps involved?

Thank you,
EC
Group: DynoMotion Message: 7944 From: Tom Kerekes Date: 7/16/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
Hi EC,

KMotionCNC doesn't have a mechanism to do Modbus from the PC.  But KFLOP has a UART and example code to communicate with ModBus.  ModBus will never be real fast but under control of KFLOP it is deterministically predictable whereas under the control of the PC, Windows, and USB it is not.

If you have a Kanalog it will convert the 3.3V KFLOP UART signals to RS232 Levels.  But in either case you will need something to convert to
RS485.  The KFLOP UART will only work up to 56K Baud and at 8 bits no parity.

The KFLOP ModBus examples are written to just continuously copy data back and forth between KFLOP and the ModBus device.  There are tables that define which ModBus Registers to Read and Write.  The ModBus example also has a concept of Loading/Unloading where after the raw ModBus registers have been transferred they can then be moved to/from KFLOP variables and Virtual IO bits and such however you wish.

So the overall process might be something like this:  a GCode S (speed) command is configured to send the Speed to a KFLOP C Program.   This is the same as if the Spindle were controlled by any other means such as a KFLOP Servo Axis or whatever.  In your case the C Program could put the desired speed into a global persist.UserData variable.  This variable would then be picked up by the ModBus code, "loaded" into a ModBus Register and then echoed out to the device.

As you can see there are a number of Steps/Layers to the process.   If anything is wrong anywhere it won't work.  So it needs to be tested from the bottom up step-by-step.

HTH
Regards
TK




Group: DynoMotion Message: 7947 From: ericncn Date: 7/16/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
Hi Tom,

I'm conscious that PC/Windows/USB would introduce some delay but still would be faster than me turning a physical knob and/or pushing physical buttons like I've done till now! :-)
And most importantly that solution would be totally software which would make my life easier:
I'm not very good at designing circuits and soldering chips... if there's an already made solution to add RS485 capability to a KFLOP please let me know.

I mean a KFLOP without KAnalog; I would like to add a KAnalog to my system but there's no room. That's why I asked (in another thread) how long could be the cables connecting the KFlop to the Kanalog (in order to install the Kanalog remotely).

56K Baud and at 8 bits no parity should be fine.
My VFD does 19 K baud 8-E-1 but I believe it is possible to change the parity settings.

Still I wonder, even though KMotionCNC hasn't built-in ModBus capability, wouldn't it be possible to e.g. call an external executable and passing parameters to it?

Or, how hard would be to port that ModBus C-code in your examples so that it works on the PC COM port instead of the KFLOP UART ?

EC

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EC,
>
> KMotionCNC doesn't have a mechanism to do Modbus from the PC.  But KFLOP has a UART and example code to communicate with ModBus.  ModBus will never be real fast but under control of KFLOP it is deterministically predictable whereas under the control of the PC, Windows, and USB it is not.
>
> If you have a Kanalog it will convert the 3.3V KFLOP UART signals to RS232 Levels.  But in either case you will need something to convert to
>
> RS485.  The KFLOP UART will only work up to 56K Baud and at 8 bits no parity.
>
>
> The KFLOP ModBus examples are written to just continuously copy data back and forth between KFLOP and the ModBus device.  There are tables that define which ModBus Registers to Read and Write.  The ModBus example also has a concept of Loading/Unloading where after the raw ModBus registers have been transferred they can then be moved to/from KFLOP variables and Virtual IO bits and such however you wish.
>
> So the overall process might be something like this:  a GCode S (speed) command is configured to send the Speed to a KFLOP C Program.   This is the same as if the Spindle were controlled by any other means such as a KFLOP Servo Axis or whatever.  In your case the C Program could put the desired speed into a global persist.UserData variable.  This variable would then be picked up by the ModBus code, "loaded" into a ModBus Register and then echoed out to the device.
>
> As you can see there are a number of Steps/Layers to the process.   If anything is wrong anywhere it won't work.  So it needs to be tested from the bottom up step-by-step.
>
> HTH
> Regards
> TK
>
>
>
>
>
>
> ________________________________
> From: ericncn <ericnc@...>
> To: DynoMotion@yahoogroups.com
> Sent: Tuesday, July 16, 2013 2:04 AM
> Subject: [DynoMotion] sending ModBus msgs from KmotionCNC to a RS485 port
>
>
>
>  
> I've bought a VFD for controlling the spindle motor speed.
> The VFD configuration software (running on PC side) talks to the VFD via an RS485 port installed on COM5, using the ModBus protocol.
>
> (The RS485 on COM5 is actually a virtual port created by an USB-RS485 converter, but this should make no difference to our purpose.)
>
> My question is: how do I send ModBus messages from KmotionCNC to the RS485 port on COM5 ?
>
> Of course I would like to implement the M commands and the S command in order to control spindle start/stop, forward/reverse, and speed.
>
> What are the main steps involved?
>
> Thank you,
> EC
Group: DynoMotion Message: 7950 From: Tom Kerekes Date: 7/16/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
Hi EC,

Well the way the PC/Windows/USB works is that 99.99% of the time the response is very fast (milliseconds), but every once in a while it can be very slow (seconds) which could actually be slower than pushing a physical button.  But I agree in your case it probably would work fine and actually if the command is coming from a Windows Screen control anyways it would have the same potential latency regardless.  But since there already is ModBus capability on KFLOP (that can also work with hard deadline cases) there isn't a lot of motivation to add it to the PC side.  You are welcome to try.  All the source code for KMotionCNC is there.  We could answer specific questions.

You should be able to find a 3.3V LVTTL to RS485 converter for $50 or less.  You would still need to make a cable to wire it up.

Regards
TK


Group: DynoMotion Message: 7958 From: ericncn Date: 7/17/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
OK, I've googled a little bit and I've found this program that does the job:
http://www.modbusdriver.com/modpoll.html

After some tinkering I can now successfully issue ModBus commands from the DOS command line to the VFD and I do manage to start/forward /reverse/stop it and change its speed.

Now I "only" have to integrate this with KmotionCNC.

As a first attempt I tried to define a user button called "START" as a PC application like:

C:\path\modpoll <parameters> COM5

but when I click on it KmotionCNC opens a pop up windows telling the program returns 1 .

I then tried to embed my command into a .BAT file, and call the .BAT file from KmotionCNC instead, but the result was the same (error for prgram returning 1).

I'm a bit lost now.

What's the proper way to invoke a .exe executable from KmotionCNC ?
Can I pass parameters to it?


Once this is solved, I know next question will be: how do I implement the "S" command? I see there's provision for it in KmotionCNC (same as various M commands) but how is the speed parameter passed?

Thank you
EC

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EC,
>
> Well the way the PC/Windows/USB works is that 99.99% of the time the response is very fast (milliseconds), but every once in a while it can be very slow (seconds) which could actually be slower than pushing a physical button.  But I agree in your case it probably would work fine and actually if the command is coming from a Windows Screen control anyways it would have the same potential latency regardless.  But since there already is ModBus capability on KFLOP (that can also work with hard deadline cases) there isn't a lot of motivation to add it to the PC side.  You are welcome to try.  All the source code for KMotionCNC is there.  We could answer specific questions.
>
>
> You should be able to find a 3.3V LVTTL to RS485 converter for $50 or less.  You would still need to make a cable to wire it up.
>
> Regards
> TK
>
>
>
>
>
> ________________________________
> From: ericncn <ericnc@...>
> To: DynoMotion@yahoogroups.com
> Sent: Tuesday, July 16, 2013 10:48 AM
> Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
>
>
>
>  
> Hi Tom,
>
> I'm conscious that PC/Windows/USB would introduce some delay but still would be faster than me turning a physical knob and/or pushing physical buttons like I've done till now! :-)
> And most importantly that solution would be totally software which would make my life easier:
> I'm not very good at designing circuits and soldering chips... if there's an already made solution to add RS485 capability to a KFLOP please let me know.
>
> I mean a KFLOP without KAnalog; I would like to add a KAnalog to my system but there's no room. That's why I asked (in another thread) how long could be the cables connecting the KFlop to the Kanalog (in order to install the Kanalog remotely).
>
> 56K Baud and at 8 bits no parity should be fine.
> My VFD does 19 K baud 8-E-1 but I believe it is possible to change the parity settings.
>
> Still I wonder, even though KMotionCNC hasn't built-in ModBus capability, wouldn't it be possible to e.g. call an external executable and passing parameters to it?
>
> Or, how hard would be to port that ModBus C-code in your examples so that it works on the PC COM port instead of the KFLOP UART ?
>
> EC
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi EC,
> >
> > KMotionCNC doesn't have a mechanism to do Modbus from the PC.  But KFLOP has a UART and example code to communicate with ModBus.  ModBus will never be real fast but under control of KFLOP it is deterministically predictable whereas under the control of the PC, Windows, and USB it is not.
> >
> > If you have a Kanalog it will convert the 3.3V KFLOP UART signals to RS232 Levels.  But in either case you will need something to convert to
> >
> > RS485.  The KFLOP UART will only work up to 56K Baud and at 8 bits no parity.
> >
> >
> > The KFLOP ModBus examples are written to just continuously copy data back and forth between KFLOP and the ModBus device.  There are tables that define which ModBus Registers to Read and Write.  The ModBus example also has a concept of Loading/Unloading where after the raw ModBus registers have been transferred they can then be moved to/from KFLOP variables and Virtual IO bits and such however you wish.
> >
> > So the overall process might be something like this:  a GCode S (speed) command is configured to send the Speed to a KFLOP C Program.   This is the same as if the Spindle were controlled by any other means such as a KFLOP Servo Axis or whatever.  In your case the C Program could put the desired speed into a global persist.UserData variable.  This variable would then be picked up by the ModBus code, "loaded" into a ModBus Register and then echoed out to the device.
> >
> > As you can see there are a number of Steps/Layers to the process.   If anything is wrong anywhere it won't work.  So it needs to be tested from the bottom up step-by-step.
> >
> > HTH
> > Regards
> > TK
> >
> >
> >
> >
> >
> >
> > ________________________________
> > From: ericncn <ericnc@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Tuesday, July 16, 2013 2:04 AM
> > Subject: [DynoMotion] sending ModBus msgs from KmotionCNC to a RS485 port
> >
> >
> >
> >  
> > I've bought a VFD for controlling the spindle motor speed.
> > The VFD configuration software (running on PC side) talks to the VFD via an RS485 port installed on COM5, using the ModBus protocol.
> >
> > (The RS485 on COM5 is actually a virtual port created by an USB-RS485 converter, but this should make no difference to our purpose.)
> >
> > My question is: how do I send ModBus messages from KmotionCNC to the RS485 port on COM5 ?
> >
> > Of course I would like to implement the M commands and the S command in order to control spindle start/stop, forward/reverse, and speed.
> >
> > What are the main steps involved?
> >
> > Thank you,
> > EC
>
Group: DynoMotion Message: 7959 From: Tom Kerekes Date: 7/18/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
Hi EC,

What KMotion Version are you running?  There was a bug running external PC programs where they would work correctly until there was an error and Abort/Stop was required.  Or even Halt/Stop of GCode.  In that case the internal Abort flag remained set and any attempt to run an external PC program would launch but then immediately Abort.  See this Thread:

http://tech.groups.yahoo.com/group/DynoMotion/message/7851

This has been fixed.  Please try the latest Test Version:

http://dynomotion.com/Software/KMotion431i.exe

But the Window's program must exit with a result of 0 indicate success.  I think there is a way to force the result code on a .BAT file.

There currently isn't a means of passing parameters to a PC Program.  We could add something.  I can't think of a good way to do it in general.  Maybe put the speed as part of the Command line?

Regards
TK

Group: DynoMotion Message: 7960 From: ericncn Date: 7/18/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
I'll check tomorrow but should be the 430 version. I'll update it.
Sure, the speed will be part of the command line. Something like this:

C:\path\modpoll -0 -1 -r 8502 -c 1 COM5 33

where the last number ("33") is the speed but of course I can't hard wire a given speed in the command. Ho do I substitute the actual speed in the command line?

I appreciate a lot your availability to add features to your program, but isn't this feature already included?
I mean if there's an option in KmotionCNC for associating an external program to the "S" command calls, there must already be a method for passing the parameter (the speed) to the external program...

Thank you,
EC

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EC,
>
> What KMotion Version are you running?  There was a bug running external PC programs where they would work correctly until there was an error and Abort/Stop was required.  Or even Halt/Stop of GCode.  In that case the internal Abort flag remained set and any attempt to run an external PC program would launch but then immediately Abort.  See this Thread:
>
> http://tech.groups.yahoo.com/group/DynoMotion/message/7851
>
> This has been fixed.  Please try the latest Test Version:
>
> http://dynomotion.com/Software/KMotion431i.exe
>
> But the Window's program must exit with a result of 0 indicate success.  I think there is a way to force the result code on a .BAT file.
>
>
> There currently isn't a means of passing parameters to a PC Program.  We could add something.  I can't think of a good way to do it in general.  Maybe put the speed as part of the Command line?
>
>
> Regards
> TK
>
>
>
> ________________________________
> From: ericncn <ericnc@...>
> To: DynoMotion@yahoogroups.com
> Sent: Wednesday, July 17, 2013 5:34 PM
> Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
>
>
>
>  
> OK, I've googled a little bit and I've found this program that does the job:
> http://www.modbusdriver.com/modpoll.html
>
> After some tinkering I can now successfully issue ModBus commands from the DOS command line to the VFD and I do manage to start/forward /reverse/stop it and change its speed.
>
> Now I "only" have to integrate this with KmotionCNC.
>
> As a first attempt I tried to define a user button called "START" as a PC application like:
>
> C:\path\modpoll <parameters> COM5
>
> but when I click on it KmotionCNC opens a pop up windows telling the program returns 1 .
>
> I then tried to embed my command into a .BAT file, and call the .BAT file from KmotionCNC instead, but the result was the same (error for prgram returning 1).
>
> I'm a bit lost now.
>
> What's the proper way to invoke a .exe executable from KmotionCNC ?
> Can I pass parameters to it?
>
> Once this is solved, I know next question will be: how do I implement the "S" command? I see there's provision for it in KmotionCNC (same as various M commands) but how is the speed parameter passed?
>
> Thank you
> EC
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi EC,
> >
> > Well the way the PC/Windows/USB works is that 99.99% of the time the response is very fast (milliseconds), but every once in a while it can be very slow (seconds) which could actually be slower than pushing a physical button.  But I agree in your case it probably would work fine and actually if the command is coming from a Windows Screen control anyways it would have the same potential latency regardless.  But since there already is ModBus capability on KFLOP (that can also work with hard deadline cases) there isn't a lot of motivation to add it to the PC side.  You are welcome to try.  All the source code for KMotionCNC is there.  We could answer specific questions.
> >
> >
> > You should be able to find a 3.3V LVTTL to RS485 converter for $50 or less.  You would still need to make a cable to wire it up.
> >
> > Regards
> > TK
> >
> >
> >
> >
> >
> > ________________________________
> > From: ericncn <ericnc@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Tuesday, July 16, 2013 10:48 AM
> > Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
> >
> >
> >
> >  
> > Hi Tom,
> >
> > I'm conscious that PC/Windows/USB would introduce some delay but still would be faster than me turning a physical knob and/or pushing physical buttons like I've done till now! :-)
> > And most importantly that solution would be totally software which would make my life easier:
> > I'm not very good at designing circuits and soldering chips... if there's an already made solution to add RS485 capability to a KFLOP please let me know.
> >
> > I mean a KFLOP without KAnalog; I would like to add a KAnalog to my system but there's no room. That's why I asked (in another thread) how long could be the cables connecting the KFlop to the Kanalog (in order to install the Kanalog remotely).
> >
> > 56K Baud and at 8 bits no parity should be fine.
> > My VFD does 19 K baud 8-E-1 but I believe it is possible to change the parity settings.
> >
> > Still I wonder, even though KMotionCNC hasn't built-in ModBus capability, wouldn't it be possible to e.g. call an external executable and passing parameters to it?
> >
> > Or, how hard would be to port that ModBus C-code in your examples so that it works on the PC COM port instead of the KFLOP UART ?
> >
> > EC
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi EC,
> > >
> > > KMotionCNC doesn't have a mechanism to do Modbus from the PC.  But KFLOP has a UART and example code to communicate with ModBus.  ModBus will never be real fast but under control of KFLOP it is deterministically predictable whereas under the control of the PC, Windows, and USB it is not.
> > >
> > > If you have a Kanalog it will convert the 3.3V KFLOP UART signals to RS232 Levels.  But in either case you will need something to convert to
> > >
> > > RS485.  The KFLOP UART will only work up to 56K Baud and at 8 bits no parity.
> > >
> > >
> > > The KFLOP ModBus examples are written to just continuously copy data back and forth between KFLOP and the ModBus device.  There are tables that define which ModBus Registers to Read and Write.  The ModBus example also has a concept of Loading/Unloading where after the raw ModBus registers have been transferred they can then be moved to/from KFLOP variables and Virtual IO bits and such however you wish.
> > >
> > > So the overall process might be something like this:  a GCode S (speed) command is configured to send the Speed to a KFLOP C Program.   This is the same as if the Spindle were controlled by any other means such as a KFLOP Servo Axis or whatever.  In your case the C Program could put the desired speed into a global persist.UserData variable.  This variable would then be picked up by the ModBus code, "loaded" into a ModBus Register and then echoed out to the device.
> > >
> > > As you can see there are a number of Steps/Layers to the process.   If anything is wrong anywhere it won't work.  So it needs to be tested from the bottom up step-by-step.
> > >
> > > HTH
> > > Regards
> > > TK
> > >
> > >
> > >
> > >
> > >
> > >
> > > ________________________________
> > > From: ericncn <ericnc@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Tuesday, July 16, 2013 2:04 AM
> > > Subject: [DynoMotion] sending ModBus msgs from KmotionCNC to a RS485 port
> > >
> > >
> > >
> > >  
> > > I've bought a VFD for controlling the spindle motor speed.
> > > The VFD configuration software (running on PC side) talks to the VFD via an RS485 port installed on COM5, using the ModBus protocol.
> > >
> > > (The RS485 on COM5 is actually a virtual port created by an USB-RS485 converter, but this should make no difference to our purpose.)
> > >
> > > My question is: how do I send ModBus messages from KmotionCNC to the RS485 port on COM5 ?
> > >
> > > Of course I would like to implement the M commands and the S command in order to control spindle start/stop, forward/reverse, and speed.
> > >
> > > What are the main steps involved?
> > >
> > > Thank you,
> > > EC
> >
>
Group: DynoMotion Message: 7961 From: ericncn Date: 7/19/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
Yup, I had the 430.
I've installed the 431i and I could implement the M3, M4, M5 codes via calls to the "modpoll" utility that sends ModBus messages to my VFD. Now the "start CW", "start CCW" and "stop" buttons in the KmotionCNC interface work as expected. I'm very happy with this.

Still, I would also like to implement the "S" command. :-)
How is the speed parameter passed ?

Please note that the VFD accepts speed in Hz while the S command takes RPM and there's also the belt ratio in the math...

I believe that in the S command setup screen there should be a field for defining the RPM/Hz ratio, same as you have counts/inch in the axes motion setup screen.

In my case the ratio would be 51
e.g. when the command "S5100" is issued,
KmotionCNC should pass the parameter "100" to the external application

Let me know,
EC

-- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EC,
>
> What KMotion Version are you running?  There was a bug running external PC programs where they would work correctly until there was an error and Abort/Stop was required.  Or even Halt/Stop of GCode.  In that case the internal Abort flag remained set and any attempt to run an external PC program would launch but then immediately Abort.  See this Thread:
>
> http://tech.groups.yahoo.com/group/DynoMotion/message/7851
>
> This has been fixed.  Please try the latest Test Version:
>
> http://dynomotion.com/Software/KMotion431i.exe
>
> But the Window's program must exit with a result of 0 indicate success.  I think there is a way to force the result code on a .BAT file.
>
>
> There currently isn't a means of passing parameters to a PC Program.  We could add something.  I can't think of a good way to do it in general.  Maybe put the speed as part of the Command line?
>
>
> Regards
> TK
>
>
>
> ________________________________
> From: ericncn <ericnc@...>
> To: DynoMotion@yahoogroups.com
> Sent: Wednesday, July 17, 2013 5:34 PM
> Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
>
>
>
>  
> OK, I've googled a little bit and I've found this program that does the job:
> http://www.modbusdriver.com/modpoll.html
>
> After some tinkering I can now successfully issue ModBus commands from the DOS command line to the VFD and I do manage to start/forward /reverse/stop it and change its speed.
>
> Now I "only" have to integrate this with KmotionCNC.
>
> As a first attempt I tried to define a user button called "START" as a PC application like:
>
> C:\path\modpoll <parameters> COM5
>
> but when I click on it KmotionCNC opens a pop up windows telling the program returns 1 .
>
> I then tried to embed my command into a .BAT file, and call the .BAT file from KmotionCNC instead, but the result was the same (error for prgram returning 1).
>
> I'm a bit lost now.
>
> What's the proper way to invoke a .exe executable from KmotionCNC ?
> Can I pass parameters to it?
>
> Once this is solved, I know next question will be: how do I implement the "S" command? I see there's provision for it in KmotionCNC (same as various M commands) but how is the speed parameter passed?
>
> Thank you
> EC
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi EC,
> >
> > Well the way the PC/Windows/USB works is that 99.99% of the time the response is very fast (milliseconds), but every once in a while it can be very slow (seconds) which could actually be slower than pushing a physical button.  But I agree in your case it probably would work fine and actually if the command is coming from a Windows Screen control anyways it would have the same potential latency regardless.  But since there already is ModBus capability on KFLOP (that can also work with hard deadline cases) there isn't a lot of motivation to add it to the PC side.  You are welcome to try.  All the source code for KMotionCNC is there.  We could answer specific questions.
> >
> >
> > You should be able to find a 3.3V LVTTL to RS485 converter for $50 or less.  You would still need to make a cable to wire it up.
> >
> > Regards
> > TK
> >
> >
> >
> >
> >
> > ________________________________
> > From: ericncn <ericnc@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Tuesday, July 16, 2013 10:48 AM
> > Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
> >
> >
> >
> >  
> > Hi Tom,
> >
> > I'm conscious that PC/Windows/USB would introduce some delay but still would be faster than me turning a physical knob and/or pushing physical buttons like I've done till now! :-)
> > And most importantly that solution would be totally software which would make my life easier:
> > I'm not very good at designing circuits and soldering chips... if there's an already made solution to add RS485 capability to a KFLOP please let me know.
> >
> > I mean a KFLOP without KAnalog; I would like to add a KAnalog to my system but there's no room. That's why I asked (in another thread) how long could be the cables connecting the KFlop to the Kanalog (in order to install the Kanalog remotely).
> >
> > 56K Baud and at 8 bits no parity should be fine.
> > My VFD does 19 K baud 8-E-1 but I believe it is possible to change the parity settings.
> >
> > Still I wonder, even though KMotionCNC hasn't built-in ModBus capability, wouldn't it be possible to e.g. call an external executable and passing parameters to it?
> >
> > Or, how hard would be to port that ModBus C-code in your examples so that it works on the PC COM port instead of the KFLOP UART ?
> >
> > EC
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi EC,
> > >
> > > KMotionCNC doesn't have a mechanism to do Modbus from the PC.  But KFLOP has a UART and example code to communicate with ModBus.  ModBus will never be real fast but under control of KFLOP it is deterministically predictable whereas under the control of the PC, Windows, and USB it is not.
> > >
> > > If you have a Kanalog it will convert the 3.3V KFLOP UART signals to RS232 Levels.  But in either case you will need something to convert to
> > >
> > > RS485.  The KFLOP UART will only work up to 56K Baud and at 8 bits no parity.
> > >
> > >
> > > The KFLOP ModBus examples are written to just continuously copy data back and forth between KFLOP and the ModBus device.  There are tables that define which ModBus Registers to Read and Write.  The ModBus example also has a concept of Loading/Unloading where after the raw ModBus registers have been transferred they can then be moved to/from KFLOP variables and Virtual IO bits and such however you wish.
> > >
> > > So the overall process might be something like this:  a GCode S (speed) command is configured to send the Speed to a KFLOP C Program.   This is the same as if the Spindle were controlled by any other means such as a KFLOP Servo Axis or whatever.  In your case the C Program could put the desired speed into a global persist.UserData variable.  This variable would then be picked up by the ModBus code, "loaded" into a ModBus Register and then echoed out to the device.
> > >
> > > As you can see there are a number of Steps/Layers to the process.   If anything is wrong anywhere it won't work.  So it needs to be tested from the bottom up step-by-step.
> > >
> > > HTH
> > > Regards
> > > TK
> > >
> > >
> > >
> > >
> > >
> > >
> > > ________________________________
> > > From: ericncn <ericnc@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Tuesday, July 16, 2013 2:04 AM
> > > Subject: [DynoMotion] sending ModBus msgs from KmotionCNC to a RS485 port
> > >
> > >
> > >
> > >  
> > > I've bought a VFD for controlling the spindle motor speed.
> > > The VFD configuration software (running on PC side) talks to the VFD via an RS485 port installed on COM5, using the ModBus protocol.
> > >
> > > (The RS485 on COM5 is actually a virtual port created by an USB-RS485 converter, but this should make no difference to our purpose.)
> > >
> > > My question is: how do I send ModBus messages from KmotionCNC to the RS485 port on COM5 ?
> > >
> > > Of course I would like to implement the M commands and the S command in order to control spindle start/stop, forward/reverse, and speed.
> > >
> > > What are the main steps involved?
> > >
> > > Thank you,
> > > EC
Group: DynoMotion Message: 7963 From: Tom Kerekes Date: 7/19/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
Hi EC,

Here is a patch that will change the GCode Interpreter to pass the S Parameter when the S Code is configured to call an external PC Program.  It is added as a decimal string.

See files here:

http://dynomotion.com/Software/Patch/PassSparamToPcProgramFromKMotionCNC431i/

Copy in the GCodeInterpreter.dll to get the new functionality.

The changed Source file is also there.

There is an example VS2008 C++ Windows Console program that when executed will read in the numeric parameter, divide it by 51, convert it to an integer, and display the result in a message box.  You might modify it to call your ModBus program with a system() call.

HTH
Regards
TK



Group: DynoMotion Message: 7966 From: ericncn Date: 7/20/2013
Subject: Re: sending ModBus msgs from KmotionCNC to a RS485 port
It works!

Thank you a lot! Really, thank you. It's rare to find people so collaborative.

Thank you also for supplying an already made VC++ project where I only have to change the code and recompile. Made me save lots of time!

Thank you again
EC

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EC,
>
> Here is a patch that will change the GCode Interpreter to pass the S Parameter when the S Code is configured to call an external PC Program.  It is added as a decimal string.
>
> See files here:
>
> http://dynomotion.com/Software/Patch/PassSparamToPcProgramFromKMotionCNC431i/
>
>
> Copy in the GCodeInterpreter.dll to get the new functionality.
>
> The changed Source file is also there.
>
> There is an example VS2008 C++ Windows Console program that when executed will read in the numeric parameter, divide it by 51, convert it to an integer, and display the result in a message box.  You might modify it to call your ModBus program with a system() call.
>
> HTH
> Regards
> TK
>
>
>
>
>
> ________________________________
> From: ericncn <ericnc@...>
> To: DynoMotion@yahoogroups.com
> Sent: Friday, July 19, 2013 5:11 AM
> Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
>
>
>
>  
> Yup, I had the 430.
> I've installed the 431i and I could implement the M3, M4, M5 codes via calls to the "modpoll" utility that sends ModBus messages to my VFD. Now the "start CW", "start CCW" and "stop" buttons in the KmotionCNC interface work as expected. I'm very happy with this.
>
> Still, I would also like to implement the "S" command. :-)
> How is the speed parameter passed ?
>
> Please note that the VFD accepts speed in Hz while the S command takes RPM and there's also the belt ratio in the math...
>
> I believe that in the S command setup screen there should be a field for defining the RPM/Hz ratio, same as you have counts/inch in the axes motion setup screen.
>
> In my case the ratio would be 51
> e.g. when the command "S5100" is issued,
> KmotionCNC should pass the parameter "100" to the external application
>
> Let me know,
> EC
>
> -- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi EC,
> >
> > What KMotion Version are you running?  There was a bug running external PC programs where they would work correctly until there was an error and Abort/Stop was required.  Or even Halt/Stop of GCode.  In that case the internal Abort flag remained set and any attempt to run an external PC program would launch but then immediately Abort.  See this Thread:
> >
> > http://tech.groups.yahoo.com/group/DynoMotion/message/7851
> >
> > This has been fixed.  Please try the latest Test Version:
> >
> > http://dynomotion.com/Software/KMotion431i.exe
> >
> > But the Window's program must exit with a result of 0 indicate success.  I think there is a way to force the result code on a .BAT file.
> >
> >
> > There currently isn't a means of passing parameters to a PC Program.  We could add something.  I can't think of a good way to do it in general.  Maybe put the speed as part of the Command line?
> >
> >
> > Regards
> > TK
> >
> >
> >
> > ________________________________
> > From: ericncn <ericnc@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Wednesday, July 17, 2013 5:34 PM
> > Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
> >
> >
> >
> >  
> > OK, I've googled a little bit and I've found this program that does the job:
> > http://www.modbusdriver.com/modpoll.html
> >
> > After some tinkering I can now successfully issue ModBus commands from the DOS command line to the VFD and I do manage to start/forward /reverse/stop it and change its speed.
> >
> > Now I "only" have to integrate this with KmotionCNC.
> >
> > As a first attempt I tried to define a user button called "START" as a PC application like:
> >
> > C:\path\modpoll <parameters> COM5
> >
> > but when I click on it KmotionCNC opens a pop up windows telling the program returns 1 .
> >
> > I then tried to embed my command into a .BAT file, and call the .BAT file from KmotionCNC instead, but the result was the same (error for prgram returning 1).
> >
> > I'm a bit lost now.
> >
> > What's the proper way to invoke a .exe executable from KmotionCNC ?
> > Can I pass parameters to it?
> >
> > Once this is solved, I know next question will be: how do I implement the "S" command? I see there's provision for it in KmotionCNC (same as various M commands) but how is the speed parameter passed?
> >
> > Thank you
> > EC
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi EC,
> > >
> > > Well the way the PC/Windows/USB works is that 99.99% of the time the response is very fast (milliseconds), but every once in a while it can be very slow (seconds) which could actually be slower than pushing a physical button.  But I agree in your case it probably would work fine and actually if the command is coming from a Windows Screen control anyways it would have the same potential latency regardless.  But since there already is ModBus capability on KFLOP (that can also work with hard deadline cases) there isn't a lot of motivation to add it to the PC side.  You are welcome to try.  All the source code for KMotionCNC is there.  We could answer specific questions.
> > >
> > >
> > > You should be able to find a 3.3V LVTTL to RS485 converter for $50 or less.  You would still need to make a cable to wire it up.
> > >
> > > Regards
> > > TK
> > >
> > >
> > >
> > >
> > >
> > > ________________________________
> > > From: ericncn <ericnc@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Tuesday, July 16, 2013 10:48 AM
> > > Subject: [DynoMotion] Re: sending ModBus msgs from KmotionCNC to a RS485 port
> > >
> > >
> > >
> > >  
> > > Hi Tom,
> > >
> > > I'm conscious that PC/Windows/USB would introduce some delay but still would be faster than me turning a physical knob and/or pushing physical buttons like I've done till now! :-)
> > > And most importantly that solution would be totally software which would make my life easier:
> > > I'm not very good at designing circuits and soldering chips... if there's an already made solution to add RS485 capability to a KFLOP please let me know.
> > >
> > > I mean a KFLOP without KAnalog; I would like to add a KAnalog to my system but there's no room. That's why I asked (in another thread) how long could be the cables connecting the KFlop to the Kanalog (in order to install the Kanalog remotely).
> > >
> > > 56K Baud and at 8 bits no parity should be fine.
> > > My VFD does 19 K baud 8-E-1 but I believe it is possible to change the parity settings.
> > >
> > > Still I wonder, even though KMotionCNC hasn't built-in ModBus capability, wouldn't it be possible to e.g. call an external executable and passing parameters to it?
> > >
> > > Or, how hard would be to port that ModBus C-code in your examples so that it works on the PC COM port instead of the KFLOP UART ?
> > >
> > > EC
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi EC,
> > > >
> > > > KMotionCNC doesn't have a mechanism to do Modbus from the PC.ÃÆ'‚  But KFLOP has a UART and example code to communicate with ModBus.ÃÆ'‚  ModBus will never be real fast but under control of KFLOP it is deterministically predictable whereas under the control of the PC, Windows, and USB it is not.
> > > >
> > > > If you have a Kanalog it will convert the 3.3V KFLOP UART signals to RS232 Levels.ÃÆ'‚  But in either case you will need something to convert to
> > > >
> > > > RS485.ÃÆ'‚  The KFLOP UART will only work up to 56K Baud and at 8 bits no parity.
> > > >
> > > >
> > > > The KFLOP ModBus examples are written to just continuously copy data back and forth between KFLOP and the ModBus device.ÃÆ'‚  There are tables that define which ModBus Registers to Read and Write.ÃÆ'‚  The ModBus example also has a concept of Loading/Unloading where after the raw ModBus registers have been transferred they can then be moved to/from KFLOP variables and Virtual IO bits and such however you wish.
> > > >
> > > > So the overall process might be something like this:ÃÆ'‚  a GCode S (speed) command is configured to send the Speed to a KFLOP C Program.ÃÆ'‚ ÃÆ'‚  This is the same as if the Spindle were controlled by any other means such as a KFLOP Servo Axis or whatever.ÃÆ'‚  In your case the C Program could put the desired speed into a global persist.UserData variable.ÃÆ'‚  This variable would then be picked up by the ModBus code, "loaded" into a ModBus Register and then echoed out to the device.
> > > >
> > > > As you can see there are a number of Steps/Layers to the process.ÃÆ'‚ ÃÆ'‚  If anything is wrong anywhere it won't work.ÃÆ'‚  So it needs to be tested from the bottom up step-by-step.
> > > >
> > > > HTH
> > > > Regards
> > > > TK
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > ________________________________
> > > > From: ericncn <ericnc@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Tuesday, July 16, 2013 2:04 AM
> > > > Subject: [DynoMotion] sending ModBus msgs from KmotionCNC to a RS485 port
> > > >
> > > >
> > > >
> > > > ÃÆ'‚ 
> > > > I've bought a VFD for controlling the spindle motor speed.
> > > > The VFD configuration software (running on PC side) talks to the VFD via an RS485 port installed on COM5, using the ModBus protocol.
> > > >
> > > > (The RS485 on COM5 is actually a virtual port created by an USB-RS485 converter, but this should make no difference to our purpose.)
> > > >
> > > > My question is: how do I send ModBus messages from KmotionCNC to the RS485 port on COM5 ?
> > > >
> > > > Of course I would like to implement the M commands and the S command in order to control spindle start/stop, forward/reverse, and speed.
> > > >
> > > > What are the main steps involved?
> > > >
> > > > Thank you,
> > > > EC